<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回错误代码的字符串描述</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.curl-share-strerror.html">« curl_share_strerror</a></li>
      <li style="float: right;"><a href="function.curl-unescape.html">curl_unescape »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.curl.html">cURL 函数</a></li>
    <li>返回错误代码的字符串描述</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.curl-strerror" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_strerror</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">curl_strerror</span> &mdash; <span class="dc-title">返回错误代码的字符串描述</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.curl-strerror-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_strerror</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$errornum</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   返回文本错误信息，解释了指定的错误代码。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-strerror-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">errornum</code></dt>

    <dd>

     <p class="para">
      <a href="http://curl.haxx.se/libcurl/c/libcurl-errors.html" class="link external">&raquo;&nbsp;cURL 错误代码</a>中的常量之一。
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-strerror-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回错误信息描述，无效的错误代码返回 <strong><code>null</code></strong> 。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.curl-strerror-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4213">
    <p><strong>示例 #1 <span class="function"><a href="function.curl-errno.html" class="function">curl_errno()</a></span> 函数的范例：</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;以错拼的&nbsp;URL&nbsp;协议创建&nbsp;curl&nbsp;句柄<br /></span><span style="color: #0000BB">$ch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"htp://example.com/"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;发送请求<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;检测错误，显示错误信息<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$errno&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$error_message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">$errno</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"cURL&nbsp;error&nbsp;(</span><span style="color: #007700">{</span><span style="color: #0000BB">$errno</span><span style="color: #007700">}</span><span style="color: #DD0000">):\n&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$error_message</span><span style="color: #007700">}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;关闭句柄<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
cURL error (1):
 Unsupported protocol
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl-strerror-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.curl-errno.html" class="function" rel="rdfs-seeAlso">curl_errno()</a> - 返回最后一次的错误代码</span></li>
    <li class="member"><span class="function"><a href="function.curl-error.html" class="function" rel="rdfs-seeAlso">curl_error()</a> - 返回当前会话最后一次错误的字符串</span></li>
    <li class="member"><a href="http://curl.haxx.se/libcurl/c/libcurl-errors.html" class="link external">&raquo;&nbsp;Curl error codes</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>